package com.hs.communication.mqtt.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqttConfig {
    public static final String MQTT_EXCHANGE_NAME = "mqtt.exchange";
    public static final String MQTT_DATA_NAME = "device.data";
    public static final String MQTT_REPLY_NAME = "device.data.reply";

    //声明主题交换机
    @Bean("mqttExchange")
    public TopicExchange mqttExchange() {
        return new TopicExchange(MQTT_EXCHANGE_NAME);
    }

    // 声明reply队列
    @Bean("deviceDataReply")
    public Queue deviceDataReply() {
        return QueueBuilder.durable(MQTT_REPLY_NAME).build();
    }

    // 声明确认队列绑定关系
    @Bean
    public Binding queueBindingReply(@Qualifier("deviceDataReply") Queue queue,
                                     @Qualifier("mqttExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(MQTT_REPLY_NAME);
    }
}
